<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * App\Models\GoldWaste
 *
 * @property int $id
 * @property int $user_id
 * @property int $gold_seed_id
 * @property int $gold_round_id
 * @property int $gold_product_id
 * @property int $product_id
 * @property int $product_sku_id
 * @property int $up_gold_record_id resold from gold record
 * @property int $round
 * @property string|null $gold_seed_title
 * @property string|null $product_title
 * @property string|null $product_cover
 * @property string|null $sku_name
 * @property string|null $sku_pic
 * @property string|null $sku_attr_value_index
 * @property string|null $sku_attr_value
 * @property string $resell_price tomorrow resell price of current record
 * @property string $record_price today current record buy price
 * @property string $record_beans beans for current record reselling fee
 * @property string $record_prize profit to parent record user
 * @property string|null $closed_at
 * @property string|null $paid_at
 * @property string|null $paid_method
 * @property string|null $to_resell_applied_at
 * @property string|null $to_split_applied_at
 * @property string|null $to_take_applied_at
 * @property int $splits_amount
 * @property int $splits_settled_amount
 * @property int $is_record_handled if user handled reselling, splitting, taking records fully
 * @property string|null $settled_at settle up record reselling or split money
 * @property string|null $rewarded_at
 * @property string|null $finished_at
 * @property string|null $deleted_at
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read \App\Models\User|null $user
 * @method static \Database\Factories\GoldWasteFactory factory(...$parameters)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste query()
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereClosedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereFinishedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereGoldProductId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereGoldRoundId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereGoldSeedId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereGoldSeedTitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereIsRecordHandled($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste wherePaidAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste wherePaidMethod($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereProductCover($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereProductId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereProductSkuId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereProductTitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereRecordBeans($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereRecordPrice($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereRecordPrize($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereResellPrice($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereRewardedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereRound($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereSettledAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereSkuAttrValue($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereSkuAttrValueIndex($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereSkuName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereSkuPic($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereSplitsAmount($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereSplitsSettledAmount($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereToResellAppliedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereToSplitAppliedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereToTakeAppliedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereUpGoldRecordId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldWaste whereUserId($value)
 * @mixin \Eloquent
 * @method static \Illuminate\Database\Query\Builder|GoldWaste onlyTrashed()
 * @method static \Illuminate\Database\Query\Builder|GoldWaste withTrashed()
 * @method static \Illuminate\Database\Query\Builder|GoldWaste withoutTrashed()
 */
class GoldWaste extends Model
{
    use HasFactory, SoftDeletes;

    protected $guarded = ['id'];

    protected $casts = [
        'sku_attr_value' => 'json',
    ];

    protected $dates = [
        'closed_at',
        'paid_at',
        'to_resell_applied_at',
        'to_split_applied_at',
        'to_take_applied_at',
        'settled_at',
        'rewarded_at',
        'finished_at',
    ];

    public function isPaid(): bool
    {
        return (bool)$this->paid_at;
    }

    public function isClosed(): bool
    {
        return (bool)$this->closed_at;
    }

    public function isSettled(): bool
    {
        return (bool)$this->settled_at;
    }

    public function isRewarded(): bool
    {
        return (bool)$this->rewarded_at;
    }

    public function isFinished(): bool
    {
        return (bool)$this->finished_at;
    }

    public function hasAppliedToResell(): bool
    {
        return (bool)$this->to_resell_applied_at;
    }

    public function hasAppliedToSplit(): bool
    {
        return (bool)$this->to_split_applied_at;
    }

    public function hasAppliedToTake(): bool
    {
        return (bool)$this->to_take_applied_at;
    }

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }
}
